<?php
    class modifyuploadimageModel extends Model{
    public function modifyuploadimageAction(){
        $id =$_SESSION["user"]["id"];
        $fileName = $_FILES["img"]["name"];
        $upload_path = "./public/upload/";
        if (!file_exists($upload_path)) {
            mkdir($upload_path);
        }

        $newname = substr_replace($fileName, date("YmdHis") . rand(100, 999), 0, strrchr(".", $fileName));
        $url = $upload_path . $newname;
        if (move_uploaded_file($_FILES["img"]["tmp_name"], $url)) {
            $photo = "http://10.2.49.1/xiaojv/Api/public/upload/" . $newname;
            $sql = "UPDATE user set avatar='{$photo}'where id='{$id}'";
           
            $result = $this->link->query($sql);

            echo json_encode(array("msg" => $result));
        } else {
            echo json_encode(array("msg" => false));
        }
    }
}

?>
